package com.neu.wangweili.servlet;

import com.alibaba.fastjson.JSONObject;
import com.neu.wangweili.service.W_ClassService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;
import java.util.Map;

@WebServlet(name = "AjaxClassServlet", urlPatterns = {"/AjaxClassServlet"})
public class AjaxClassServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        response.setCharacterEncoding("UTF-8");
        String d_id=request.getParameter("d_id");
        W_ClassService w_classService=new W_ClassService();
        List<Map<String,Object>>list=w_classService.findBydeptId(d_id);
        String str="";
        if(list.size()>0){
            str=JSONObject.toJSONString(list);
        }

        PrintWriter out=response.getWriter();
//        因为前段获取数据时指明了数据的格式为Json
//        所以后天返回时数据必须是Json格式
        out.write(str);
        out.close();
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doPost(request, response);
    }
}
